<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    template="/layout/admin_template.xhtml">

    <ui:define name="body">
    	<h:form>
    		<rich:panel id="e_id">
    			<f:facet name="header"><h:outputText value="#{messages.e_item_msg}" /></f:facet>
	    		<table>
	    			<tr>
	    				<td valign="top">
				    		<table>
				    			<tr>
				    				<td colspan="2">
							    		<h:commandButton value="#{messages.back_msg}" action="item" immediate="true"/>
							    		<rich:spacer width="10" />
							    		<a:commandButton value="#{messages.save_msg}" action="#{kItemManager.save()}" reRender="e_id"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.application_msg}" />
				    					<span class="m">*</span>
				    				</td>
				    				<td>
				    					<h:selectOneMenu value="#{kItemManager.applicationId}" required="true" >
				    						<f:selectItems value="#{kItemManager.applications}" />
				    					</h:selectOneMenu>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.item_type_msg}" />
				    					<span class="m">*</span>
				    				</td>
				    				<td>
				    					<h:selectOneMenu value="#{kItemManager.itemTypeId}" required="true">
				    						<f:selectItems value="#{kItemManager.itemTypes}" />
				    					</h:selectOneMenu>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.valid_from_msg}:" />
				    					<span class="m">*</span>
				    				</td>
				    				<td>
				    					<rich:calendar value="#{kItemManager.item.validFrom}" required="true" showWeeksBar="false"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.valid_to_msg}:" />
				    					<span class="m">*</span>
				    				</td>
				    				<td>
				    					<rich:calendar value="#{kItemManager.item.validTo}" required="true" showWeeksBar="false"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.active_msg}" />
				    				</td>
				    				<td>
				    					<h:selectBooleanCheckbox value="#{kItemManager.item.active}" />
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.kadrons_msg}" />
				    					<span class="m">*</span>
				    				</td>
				    				<td>
				    					<h:inputText value="#{kItemManager.item.kadrons}" size="4" required="true" maxlength="4"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td height="20px"></td>
				    			</tr>
				    			<tr>
				    				<td colspan="2">
				    					<table>
				    						<tr>
				    							<td></td>
				    							<td>
							    					<h:outputText value="#{messages.price_msg}" title="#{messages.price_msg}" />
				    							</td>
				    							<td>
							    					<h:outputText value="#{messages.tax_price_msg}" title="#{messages.tax_price_msg}" />
				    							</td>
				    						</tr>
				    						<ui:param name="kSize" value="#{kItemManager.kiPrices.keys.size}" />
						   					<a:repeat value="#{kItemManager.kiPrices.keys}" var="e" rowKeyVar="s">
								    			<tr>
								    				<td>
								    					<h:outputText value="#{e.code}:" title="#{e.getName(klang)}" />
								    					<span class="m">*</span>
								    				</td>
								    				<td>
								    					<h:inputText value="#{kItemManager.kiPrices.get(e).price}" tabindex="#{s+1}" required="true" size="6" styleClass="tar"/>
								    				</td>
								    			</tr>
						   					</a:repeat>
				    					</table>	
				    				</td>
				    			</tr>
				    		</table>
	    				</td>
	    				<td valign="top">
	    					<table>
				    			<tr>
				    				<td colspan="2">
				    					<a:commandButton value="#{messages.avalable_msg}" action="#{kItemManager.avb()}" 
				    						rendered="#{kItemManager.item.saved}" immediate="true"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.color_msg}:" />
				    				</td>
				    				<td>
				    					<h:outputText value="#{kItemManager.colors.{d|d.color.color.getName(klang)}}" rendered="#{kItemManager.colors.size gt 0}"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.size_msg}:" />
				    				</td>
				    				<td>
				    					<h:outputText value="#{kItemManager.sizes.{d|d.size.size.code}}" rendered="#{kItemManager.sizes.size gt 0}"/>
				    				</td>
				    			</tr>
				    			<tr>
				    				<td>
				    					<h:outputText value="#{messages.material_msg}:" />
				    				</td>
				    				<td>
				    					<h:outputText value="#{kItemManager.materials.{d|d.material.material.getName(klang)}}" rendered="#{kItemManager.materials.size gt 0}"/>
				    				</td>
				    			</tr>
	    					</table>
	    				</td>
	    			</tr>
	    		</table>
	    		<table>
	    			<tr>
	    				<td>
				    		<ui:include src="/pages/in/k_translate.xhtml" >
				    			<ui:param name="item" value="#{kItemManager.item}" />
				    		</ui:include>
	    				</td>
	    			</tr>
	    		</table>
    		</rich:panel>
    	</h:form>
    	<br />
   		<c:if id="img_id" rendered="#{kItemManager.item.saved}">
	   		<rich:panel>
	  			<f:facet name="header">
					<h:outputText value="#{messages.upload_images_msg}" />
				</f:facet>
			   	<h:form>
			   		<a:outputPanel id="images_id">
			    		<rich:fileUpload id="upload_id"
			    			autoclear="true"
			    			noDuplicate="true"
			    			sizeErrorLabel="TOO BIG"
			    			acceptedTypes="PNG,JPG" 
			    			listHeight="50"
			    			fileUploadListener="#{kItemManager.processUpload}" >
			    			<a:support event="onuploadcomplete" action="#{kItemManager.loadImages()}" reRender="images_id"/>
			    		</rich:fileUpload>
			    		<br />
			    		<br />
			    		<a:outputPanel id="dt_id">
				   			<rich:dataTable id="img_table" value="#{kItemManager.images}" var="img">
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.img_msg}" />
				   					</f:facet>
				   					<a href="/#{kInitParam.imgPath}/i_#{img.itemId}/#{img.name}" target="blank_">
				  						<img src="/#{kInitParam.imgPath}/i_#{img.itemId}/#{img.name}" width="50" height="50"/>
						   			</a>
				   				</rich:column>
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.name_msg}" />
				   					</f:facet>
				  						<h:outputText value="#{img.name}" />
				   				</rich:column>
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.main_msg}" />
				   					</f:facet>
				  					<table align="center">
				   						<tr>
				   							<td>
						  						<a:commandLink action="#{kItemManager.mainImg(img)}" reRender="images_id" immediate="true">
							   						<h:graphicImage value="/img/#{img.main?'star':'star-empty'}.png" 
							   							title="#{messages.main_msg}" alt="#{messages.main_msg}" />
												</a:commandLink>
				   							</td>
				   						</tr>
				   					</table>
				   				</rich:column>
				   				<!-- 
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.color_msg}" />
				   					</f:facet>
				   					<s:fragment rendered="#{kItemManager.colors.size gt 0}">
				   						<h:selectOneMenu value="#{img.color}" valueChangeListener="#{kItemManager.processValueChange}">
				    						<s:selectItems value="#{kItemManager.colors}" var="e" 
				    							label="#{e.color.color.getName(klang)}" 
				    							noSelectionLabel=" "/>
				    						<s:convertEntity />
				    						<f:attribute name="img" value="#{img}"/>
				    						<a:support event="onchange" reRender="dt_id" />
				    					</h:selectOneMenu>
				   					</s:fragment>
				   				</rich:column>
				   				 -->
				   				<rich:column id="uc_id">
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.upload_thumb_msg}" />
				   					</f:facet>
				   					<a:outputPanel id="tc_id">
					   					<s:fragment rendered="#{empty img.thumb}">
						   					<rich:fileUpload
								    			autoclear="true"
								    			noDuplicate="true"
								    			sizeErrorLabel="TOO BIG"
								    			acceptedTypes="PNG,JPG" 
								    			listHeight="50"
								    			fileUploadListener="#{kItemManager.uploadThumb}" >
								    			<f:attribute name="imageId" value="#{img.id}"/>
								    			<a:support event="onuploadcomplete" action="#{kItemManager.loadImages()}" reRender="images_id"/>
								    		</rich:fileUpload>
					   					</s:fragment>
					   					<s:fragment rendered="#{not empty img.thumb}">
					   						<a href="/#{kInitParam.imgPath}/i_#{img.itemId}/#{img.thumb}" target="blank_">
						  						<img src="/#{kInitParam.imgPath}/i_#{img.itemId}/#{img.thumb}" width="50" height="50"/>
								   			</a>
					   						<h:outputText value="#{img.thumb}" />
						   					<a:commandLink action="#{kItemManager.deleteThumb(img)}"
						   						reRender="images_id" immediate="true">
						   						<h:graphicImage value="/img/cross.png" title="#{messages.delete_msg}" />
    										</a:commandLink>
					   					</s:fragment>
				   					</a:outputPanel>
				   				</rich:column>
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.do_msg}" />
				   					</f:facet>
				   					<h:panelGroup>
					   					<a:commandLink action="#{kItemManager.deleteImg(img)}"
					   						reRender="images_id" immediate="true">
						   					<h:graphicImage value="/img/cross.png" title="#{messages.delete_msg}" />
					    				</a:commandLink>
				   					</h:panelGroup>
				   				</rich:column>
				   				<f:facet name="footer">
				   					<rich:datascroller renderIfSinglePage="false"/>
				   				</f:facet>
				   			</rich:dataTable>
			    		</a:outputPanel>
			   		</a:outputPanel>
			   	</h:form>
			</rich:panel>
   		</c:if>
    </ui:define>
</ui:composition>
